from config import URL
import logging


class RechargeApi:

    def __init__(self, session):
        # 接收session对象的变量
        self.session = session

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        url = URL + f"/common/public/verifycode/{r}"
        resp = self.session.get(url=url)
        print(f'获取充值验证码接口返回状态码:{resp.status_code}')
        logging.info(f'获取充值验证码接口返回状态码:{resp.status_code}')
        return resp

    # 充值接口
    def recharge(self, amount_v, valicode_v, paymentType_v="chinapnrTrust", formStr_v="reForm"):
        # 定义一个字典变量，用来接收请求体数据
        url = URL + "/trust/trust/recharge"
        form_dict = {"paymentType": paymentType_v, "amount": amount_v, "formStr": formStr_v, "valicode": valicode_v}
        resp = self.session.post(url=url, data=form_dict)
        print(f'充值接口返回响应体数据:{resp}')
        logging.info(f'充值接口返回响应体数据:{resp.json()}')
        return resp

    # 第三方充值接口
    def third_recharge(self, url, form_dict):
        resp = self.session.post(url=url, data=form_dict)
        print(f'第三方充值接口:{resp.text}')
        logging.info(f'第三方充值接口:{resp.text}')
        return resp
